#include <memory>
#include <iostream>
#include "clang/Tooling/CommonOptionsParser.h"
#include "ClassDiagramAnalyzer.hpp"
#include <clang/Tooling/JSONCompilationDatabase.h>
#include <string>

#include "framework/ASTManager.h"

std::map<std::string,Record*> Record::recordDB;

static llvm::cl::OptionCategory MyToolCategory("My tool options");
static llvm::cl::extrahelp CommonHelp(clang::tooling::CommonOptionsParser::HelpMessage);
int main(int argc, char const* argv[])
{

	std::vector<std::string> ASTs = initialize(argv[1]);

	Config configure(argv[2]);
	std::string path = configure.getOptionBlock("ClassDiagramChecker").find("path")->second;
	ASTResource resource;
  	ASTManager manager(ASTs, resource, configure);
	
	std::vector<ASTFile *> astFiles = resource.getASTFiles();

	for(ASTFile * astFile : astFiles){
		// std::cout<<astFile->getAST()<<std::endl;
		ASTUnit * astUnit = manager.getASTUnit(astFile);
		ASTContext& AST = astUnit->getASTContext();
		ClassDiagramVisitor cdv(&AST,path);
		cdv.HandleTranslationUnit(AST);

		/*
		std::map<std::string,Record*> temp = cdv.getRecordDB();
		std::map<std::string,Record*>::iterator iter;  
    		for(iter = temp.begin(); iter != temp.end(); iter++){
			std::cout<<"class: "<<iter->first<<std::endl; 
		} 
       		*/
		
	}
    
	bool showData = configure.getOptionBlock("ClassDiagramChecker").find("showData")->second == "true";
	bool showDependency = configure.getOptionBlock("ClassDiagramChecker")
		.find("showDependency")->second == "true";
	Record::printAsDot(showData, showDependency);
	return 0;
}
